/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.packet.server;

import java.io.IOException;

import lineage.core.Opcodes;
import lineage.model.gametime.L1GameTimeClock;
import lineage.model.instance.L1PcInstance;
import lineage.packet.L1AbstractPacketServer;

/**
 * 角色属性与能力值(自身).
 * 
 * @version 2014年3月16日下午3:39:21
 * @author jrwz
 */
public final class S_CharStatusOwn extends L1AbstractPacketServer {
    private byte[] _byte = null;

    /**
     * 角色属性与能力值(自身).
     * 
     * @param pc
     *            - 要更新的对象
     */
    public S_CharStatusOwn(final L1PcInstance pc) {
        int time = L1GameTimeClock.getInstance().currentTime().getSeconds();
        time = time - (time % 300);
        writeC(Opcodes.S_OPCODE_OWN_CHAR_STATUS);
        writeD(pc.getId()); // id
        writeC(pc.getLevel()); // 等级
        writeExp(pc.getExp()); // 经验值
        writeC(pc.getStr()); // 力量值
        writeC(pc.getInt()); // 智力值
        writeC(pc.getWis()); // 精神值
        writeC(pc.getDex()); // 敏捷值
        writeC(pc.getCon()); // 体质值
        writeC(pc.getCha()); // 魅力值
        writeH(pc.getHp()); // 当前hp
        writeH(pc.getMaxHP()); // 最高hp
        writeH(pc.getMp()); // 当前mp
        writeH(pc.getMaxMP()); // 最高mp
        writeC(pc.getAc()); // 物理防御
        writeD(time); // 时间
        writeC(pc.getFood()); // 饱食度226
        writeC(pc.getWeight()); // 负重程度
        writeH(pc.getLawful()); // 正义值
        writeC(pc.getFire()); // 火属性
        writeC(pc.getWater()); // 水属性
        writeC(pc.getWind()); // 风属性
        writeC(pc.getEarth()); // 地属性
    }

    @Override
    public byte[] getContent() throws IOException {
        if (this._byte == null) {
            this._byte = this.getBytes();
        }
        return this._byte;
    }
}
